<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>设备定时开关管理</title>
    <meta name="decorator" content="nblank"/>
    <%@include file="/WEB-INF/views/include/treetable.jsp" %>
    <link href="${ctxStatic}/modules/biz/record/equItemHisList.css" rel="stylesheet" itself="true" />
</head>
<body>
<div class="content container">
    <h2 class="page-title">设备定时开关管理
    </h2>
    <div class="row">
        <div class="col-md-12">
            <section class="widget widget-tabs">
                <header>
                    <ul class="nav nav-tabs">
                        <li><a href="${ctx}/biz/switcher?officeId=${officebiz.id}">${officebiz.name}定时开关列表</a></li>
                        <li class="active"><a href="javascript:;">${officebiz.name}定时开关${not empty param.id?'修改':'添加'}</a></li>
                    </ul>
                </header>
                <div class="body tab-content">
                    <div class="tab-pane active clearfix" style="position: relative;">
                        <form:form id="inputForm" modelAttribute="equSwitcher" action="${ctx}/biz/switcher/save" method="post"
                                   class="form-horizontal">
                            <form:hidden path="id"/>
                            <input type="hidden" id="officeId" value="${officebiz.id}">
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span style="color:red;">*</span>站组:</label>
                                <div class="col-sm-8 text-lefts">${equSwitcher.sgroupName}</div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span>设备:</span></label>
                                <div class="col-sm-8 text-lefts">${equSwitcher.gitemName}</div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span>周:</span></label>
                                <div class="col-sm-8 ">
                                    <div class="checkbox">
                                        <form:checkboxes path="turnWeekArray" items="${fns:getDictList('sys_week')}" itemValue="value" itemLabel="label"></form:checkboxes>
                                    </div>
                                    <span name="tip" style="font-weight: bold"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span class="help-inline">时:</span></label>
                                <div class="input-group date timeb1 col-sm-2" id="thour" data-link-field="thour">
                                    <form:input path="turnHour" htmlEscape="false" maxlength="10" readonly="true" size="32" value="${not empty equSwitcher.turnHour?turnHour:0}" class="form-control input-transparent"/>
                                    <div class="input-group-addon"><span class="glyphicon glyphicon-time"></span></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span class="help-inline">分:</span></label>
                                <div class="input-group date timeb1 col-sm-2" id="tminute" data-link-field="tminute">
                                    <form:input path="turnMinute" htmlEscape="false" maxlength="10" readonly="true" size="32" value="${not empty equSwitcher.turnMinute?turnMinute:0}" class="form-control input-transparent"/>
                                    <div class="input-group-addon"><span class="glyphicon glyphicon-time"></span></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span class="help-inline">动作:</span></label>
                                <div class="col-sm-2">
                                    <form:select path="operate" class="selectpicker"  data-style="btn-primary"
                                                 items="${fns:getDictList('biz_equ_switcher_operate')}" itemValue="value" itemLabel="label" htmlEscape="false">
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span class="help-inline">是否生效:</span></label>
                                <div class="col-sm-2">
                                    <form:select path="active" class="selectpicker"  data-style="btn-primary"
                                                 items="${fns:getDictList('switcher_active')}" itemValue="value" itemLabel="label" htmlEscape="false">
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-4"><span class="help-inline">备注:</span></label>
                                <div class="col-sm-4">
                                    <form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="form-control input-transparent"/>
                                </div>
                            </div>

                            <div class="form-actions">
                                <div class="text-align-center">
                                    <input id="btnCancel" class="btn btn-default" type="button"
                                           style="margin-left: -50px;min-width:100px;" value="返 回" onclick="history.go(-1)"/>
                                    <input id="btnSubmit" class="btn btn-primary" style="margin-left:50px;min-width:100px;"
                                           type="submit" value="保 存"/>&nbsp;
                                </div>
                            </div>
                        </form:form>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        // 进入本页面的默认设置
        if($("#sgroupId").val()!=''){
            $("#gitemId").attr("disabled", true);//设备选择器不可用
        }

        // 站组change事件
        $('#sgroupId').on('changed.bs.select', function () {
            $("#gitemId").attr("disabled", true);
            $("#gitemId option:not(:first)").remove();
            if($('#sgroupId').val()==""){
                $("#gitemId").change().selectpicker('refresh');
            } else {
                $.ajax({
                    type:"get",
                    url:"${ctx}/biz/sgcfg/itemlist",
                    data:{
                        sgroupId:$('#sgroupId').val()
                    },
                    dataType:"json",
                    success:function(data){
                        $.each(data, function(indexColumn, item){
                            $("<option value='" + item.gitem.id + "'>" + item.gitem.name + "</option>").appendTo("#gitemId");
                        })
                        $("#gitemId").attr("disabled", false);
                        $("#gitemId").change().selectpicker('refresh');
                    }
                });
            }
        });


//        设备查询的change事件
        $('#gitemId').on('changed.bs.select', function (e) {
            console.info('-------'+$('#gitemId').val());
        });

        $("#inputForm").validate({
            ignore: "",
            focusInvalid : true,
            rules:{
                "sgroupId":{
                    required:true
                },
                "gitemId":{
                    required:true
                },
                "turnWeekArray":{
                    required:true
                }
            },
            messages:{
                "sgroupId":{
                    required:"必选信息"
                },
                "gitemId":{
                    required:"必选信息"
                },
                "turnWeekArray":{
                    required:"必选信息"
                }
            },
            errorPlacement: function(error, element) {
//                error.appendTo(element.parent().parent().parent().find("span[name='tip']"));
                error.appendTo(element.parent());
//                element.parent().parent().parent().find("span[name='tip']")[0].innerHTML = error[0].innerHTML;
            },
            submitHandler: function (form) {
                $(form).find(":submit").attr("value", "提交中...");
                $(form).ajaxSubmit({
                    success: function (result) {
                        Messenger().post("操作成功!");
                        pxTrigDlg("${ctx}/biz/switcher?officeId="+$('#officeId').val());
                    }
                });
            }
        });
    });
</script>
<script type="text/javascript" src="${ctxStatic}/datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="${ctxStatic}/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript">
    $('#thour').datetimepicker({
        autoclose:true,
        format: "h",
        language:  'zh-CN',
        startView: 1,
        minView: 1,
        maxView: 1,
        forceParse: 0,
        linkFormat: "h"
    });
    $('#tminute').datetimepicker({
        disabled:true,
        autoclose:true,
        format: "i",
        language:  'zh-CN',
        startView: 0,
        minView: 0,
        maxView: 0,
        forceParse: 0,
        linkFormat: "i"
    });
</script>
</body>
</html>